﻿using System;
using System.Net.Http;
using Common.Logging;
using In.Api.Dto.YBWs;
using Newtonsoft.Json;
using Out.Service.HttpClients;

namespace Out.Service.Services
{
    public static class YbPayService
    {

        private static readonly ILog Logger = LogManager.GetLogger(typeof(BizApptOrder));
        /// <summary>
        /// 取消医保
        /// </summary>
        /// <param name="cardNo">医保卡号码</param>
        /// <param name="Jydjh">就医登记号</param>
        /// <returns>1表示取消成功</returns>
        public static  int YbRefund(string cardNo, string Jydjh)
        {
            #region 取消医保
            var request = new YBReturnChargesRequest();
            request.CardNo = cardNo;
            request.Jydjh = Jydjh;

           YBReturnChargesResponse response;
            try
            {
                var httpClient = InHttpClient.GetClient();
                var responseMsg = httpClient.PostAsJsonAsync("YBWs/YBReturnCharges", request).Result;
                responseMsg.EnsureSuccessStatusCode();
                response = responseMsg.Content.ReadAsAsync<YBReturnChargesResponse>().Result;
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("调用院内取消医保Api出错,信息：{0}", JsonConvert.SerializeObject(ex));
                return 0;
            }

            if (response.ResultCode == "0")
            {
                return 1;
            }
            return 0;
            #endregion
        }
    }
}
